<?php
    //include_once 'init.php';
if(!empty($_POST)){
            $id=$_POST['id'];//id
            $password1=$_POST['password1'];//原密码
            $password2=$_POST['password2'];//新密码
            $password3=$_POST['password3'];//确认密码
            $level=$_POST['level'];//作者
            $update_time=time();//修改时间
            //做判断是否需要修改密码
            if(!empty($password1) && !empty($password2) && !empty($password3)){
                if($password2!=$password3){
                    echo '<script>alert("修改的密码不一致");history.go(-1);</script>';die;
                }
                $sql="select * from `admin` where `password` = md5($password1)";
                $result=mysqli_query($link,$sql);
                $data = mysqli_fetch_assoc($result);
                if(empty($data)){
               echo '<script>alert("原密码错误");history.go(-1);</script>';die;
                }
                $password3=md5($password3);
                $pwd = "`password`='$password3',";
            }else{
                $pwd='';
            }
       mysqli_query($link, 'set names utf8');
       $sql="update `admin` set  $pwd `level`='$level',`update_time`='$update_time' where `id`=$id";
       mysqli_query($link,$sql);
       $result=mysqli_affected_rows($link);
       if($result>0){
        echo '<script>alert("管理员修改成功");location.href="index.php?c=admin&a=list&admin=1";</script>';die;
    }else{
        echo '<script>alert("管理员修改失败");history.go(-1);</script>';die;
    }
}
$id=$_GET['id'];
$sql="select * from `admin` where `id`=$id";
$result=mysqli_query($link,$sql);
$data=mysqli_fetch_assoc($result);

include(VIEW_PATH.$admin.'layout.html');
?>